import os
class Utils():
    @staticmethod
    def get_path(path:str,type:str = "dir",recursion:bool = False,has_root:bool = False):
        '''
        获取目录下的数据
        :param path: 目录
        :param type: 类型dir/file/all
        :param recursion: 是否递归
        :param has_root: 是否拼接root
        :return:
        '''
        res = []
        if recursion:
            for root, dirs, files in os.walk(path):
                if type == "file":
                    for file in files:
                        if has_root:
                            file = os.path.join(root, file)
                        res.append(file)
                elif type == "dir":
                    for dir in dirs:
                        if has_root:
                            dir = os.path.join(root, dir)
                        res.append(dir)
                else:
                    for file in files:
                        if has_root:
                            file = os.path.join(root, file)
                        res.append(file)
                    for dir in dirs:
                        if has_root:
                            dir = os.path.join(root, dir)
                        res.append(dir)
        else:
            res = os.listdir(path)
            if type == "file":
                res = [file for file in res if os.path.isfile(os.path.join(path, file))]
            elif type == "dir":
                res = [dir for dir in res if os.path.isdir(os.path.join(path, dir))]
            else:
                res = [file for file in res if os.path.isfile(os.path.join(path, file))]
                res += [dir for dir in res if os.path.isdir(os.path.join(path, dir))]
        return res